<template>
	<div>
		<cl-crud @load="onLoad">
			<template #slot-filter>
				<div class="nav base-flex">
					<div class="nav-li">
						<filterGstatus
							@change="
								val =>
									refresh({
										status: val
									})
							"
						></filterGstatus>
					</div>
					<div class="nav-li">
						活动时间：
						<date-picker
							@change="
								val => refresh({ startTime: val[0], endTime: val[1], page: 1 })
							"
							@refresh="refresh({ startTime: '', endTime: '', page: 1 })"
						></date-picker>
					</div>
					<div class="nav-li">
						<span style="font-size:12px">是否置顶：</span>
						<el-select
							size="mini"
							filterable
							placeholder="是否置顶"
							style="margin-right: 1em;width:100px;"
							v-model="filterSelectVal.isTop"
							@change="val => crud.refresh({ top: val, page: 1 })"
						>
							<el-option value label="全部"></el-option>
							<el-option label="是" :value="1"></el-option>
							<el-option label="否" :value="0"></el-option>
						</el-select>
					</div>
					<div class="nav-li">
						<span style="font-size:12px">分类：</span>
						<el-select
							size="mini"
							class="el-select"
							v-model="selects.specialType"
							placeholder="请选择"
							@change="
								val =>
									crud.refresh({
										floorId: val
									})
							"
						>
							<el-option label="全部" value=""></el-option>
							<el-option
								v-for="item in options.specialTypeOp"
								:key="item.value"
								:label="item.label"
								:value="item.value"
							></el-option>
						</el-select>
					</div>
					<div class="nav-li">
						<span style="font-size:12px">是否限时秒杀：</span>
						<el-select
							size="mini"
							filterable
							placeholder="是否置顶"
							style="margin-right: 1em;width:100px;"
							v-model="filterSelectVal.isSpecial"
							@change="val => crud.refresh({ isSpecial: val, page: 1 })"
						>
							<el-option value label="全部"></el-option>
							<el-option label="是" :value="1"></el-option>
							<el-option label="否" :value="0"></el-option>
						</el-select>
					</div>
					<div class="nav-li">
						<span style="font-size:12px">是否榜单好货：</span>
						<el-select
							size="mini"
							filterable
							placeholder="是否置顶"
							style="margin-right: 1em;width:100px;"
							v-model="filterSelectVal.isTopList"
							@change="val => crud.refresh({ isTopList: val, page: 1 })"
						>
							<el-option value label="全部"></el-option>
							<el-option label="是" :value="1"></el-option>
							<el-option label="否" :value="0"></el-option>
						</el-select>
					</div>
				</div>
			</template>
			<template #slot-filter2>
				<div class="nav-li">
					<div style="font-size:12px">优惠券：</div>
					<el-input-number
						v-model="options.couponMoneyStart"
						controls-position="right"
						style="width:80px;"
						size="mini"
					></el-input-number>
					<div style="margin:0px 10px">-</div>
					<el-input-number
						v-model="options.couponMoneyEnd"
						controls-position="right"
						style="width:80px;"
						size="mini"
					></el-input-number>
					<el-button
						style="margin-left:1em"
						size="mini"
						@click="
							crud.refresh({
								couponMoneyStart: options.couponMoneyStart,
								couponMoneyEnd: options.couponMoneyEnd
							})
						"
						>确定</el-button
					>
				</div>
				<div class="nav-li">
					<div style="font-size:12px">券后价：</div>
					<el-input-number
						v-model="options.price1"
						controls-position="right"
						style="width:80px;"
						size="mini"
					></el-input-number>
					<div style="margin:0 10px">-</div>
					<el-input-number
						v-model="options.price2"
						controls-position="right"
						style="width:80px;"
						size="mini"
					></el-input-number>
					<el-button
						style="margin-left:1em"
						size="mini"
						@click="
							crud.refresh({
								epStartPrice: options.price1,
								epEndPrice: options.price2
							})
						"
						>确定</el-button
					>
				</div>
				<div class="nav-li">
					<span style="font-size:12px">商品平台：</span>
					<el-select
						size="mini"
						filterable
						placeholder="商品平台"
						style="margin-right: 1em;width:100px;"
						v-model="filterSelectVal.appType"
						@change="val => crud.refresh({ goodSource: val, page: 1 })"
					>
						<el-option value label="全部"></el-option>
						<el-option label="京东" :value="1"></el-option>
						<el-option label="拼多多" :value="2"></el-option>
					</el-select>
				</div>
				<div class="nav-li">
					<span style="font-size:12px">是否榜单好货置顶：</span>
					<el-select
						size="mini"
						filterable
						style="margin-right: 1em;width:100px;"
						v-model="filterSelectVal.isTopListLevel"
						@change="val => crud.refresh({ isTopListLevel: val, page: 1 })"
					>
						<el-option value label="全部"></el-option>
						<el-option label="是" :value="1"></el-option>
						<el-option label="否" :value="0"></el-option>
					</el-select>
				</div>
				<div class="nav-li">
					<span style="font-size:12px">是否活动商品：</span>
					<el-select
						size="mini"
						filterable
						style="margin-right: 1em;width:100px;"
						v-model="filterSelectVal.isActivity"
						@change="val => crud.refresh({ isActivity: val, page: 1 })"
					>
						<el-option value label="全部"></el-option>
						<el-option label="是" :value="1"></el-option>
						<el-option label="否" :value="0"></el-option>
					</el-select>
				</div>
			</template>
			<template #slot-add>
				<el-button size="mini" @click="jdLnput('jd')">京东录入商品</el-button>
			</template>
			<template #slot-viewType>
				<el-button size="mini" @click="pddLnput()" style="margin-right:1em"
					>拼多多录入商品</el-button
				>
				<el-button type="text" size="mini" @click="openForm_CRUD" style="margin-right:1em"
					>查看分类</el-button
				>
				<el-button size="mini" @click="jdPutWayGoods('jd')" style="margin-right:1em"
					>京东自动上品规则配置</el-button
				>
				<el-button size="mini" @click="jdPutWayGoods('pdd')" style="margin-right:1em"
					>拼多多自动上品规则配置</el-button
				>
			</template>
			<template #slot-setSort="{scope}">
				<p class="setsort" @click="setGoodsort(scope.row)">修改</p>
			</template>
			<template #slot-delete="{scope}">
				<delBtn @del="crud.delete(scope.row)"></delBtn>
			</template>
			<template #table-column-goodInfo="{scope}">
				<jd-good-info :item="scope.row"></jd-good-info>
			</template>
			<template #table-column-couponInfo="{scope}">
				<coupon-info :item="scope.row"></coupon-info>
			</template>
			<template #table-column-isTopListLevel="{scope}">
				<div v-if="scope.row.isTopListLevel > 0">
					是(序号{{ scope.row.isTopListLevel }})
				</div>
				<div v-else>否</div>
			</template>
			<template #table-column-status="{scope}">
				<div>
					<el-tag v-if="scope.row.status == 1" type="success">正常</el-tag>
					<el-tooltip
						class="item"
						effect="dark"
						:content="scope.row.reason"
						placement="top"
						v-if="scope.row.status == 2"
					>
						<el-tag type="info">已下架</el-tag>
					</el-tooltip>
				</div>
			</template>
			<!-- <template #table-column-isSpecial="{scope}">
				<el-tag v-if="scope.row.isSpecial == 1" type="success">是</el-tag>
				<el-tag v-if="scope.row.isSpecial == 0" type="info">否</el-tag>
			</template> -->
			<template #table-column-isTopList="{scope}">
				<el-tag v-if="scope.row.isTopList == 1" type="success">是</el-tag>
				<el-tag v-if="scope.row.isTopList == 0" type="info">否</el-tag>
			</template>

			<template #table-column-activityId="{scope}">
				<el-tag v-if="scope.row.activityId != 0" type="success">是</el-tag>
				<el-tag v-if="scope.row.activityId == 0" type="info">否</el-tag>
				<div>{{ scope.row.activityName }}</div>
			</template>

			<!-- 数据统计 -->
			<template #table-column-count="{scope}">
				<div class="column-count">
					<p>
						免单金额：
						<span>{{ scope.row.mdMoney | toFixed(2) }}</span>
					</p>
					<p>
						京礼金金额：
						<span>{{ scope.row.jljMoney | toFixed(2) }}</span>
					</p>
					<p>
						总数：
						<span>{{ scope.row.total }}</span>
					</p>
					<p>
						剩余数量：
						<span>{{ scope.row.surplus }}</span>
					</p>
				</div>
			</template>

			<!-- 活动时间 -->
			<template #table-column-date="{scope}">
				<p>活动开始时间：{{ (scope.row.startTime * 1000) | date_format }}</p>
				<p>活动结束时间：{{ (scope.row.endTime * 1000) | date_format }}</p>
			</template>
			<template #table-column-type="{scope}">
				<div v-if="scope.row.type == 0">零元购</div>
				<div v-if="scope.row.type == 1">限时抢购</div>
				<div v-if="scope.row.type == 2">新人专享</div>
				<div v-if="scope.row.type == 3">百亿补贴</div>
				<div v-if="scope.row.type == 4">大转盘</div>
				<div v-if="scope.row.type == 5">微信京礼金</div>
			</template>
		</cl-crud>

		<cl-form ref="cl-form"></cl-form>
		<cl-form ref="cl-form2"></cl-form>
		<pddGoodsLnput ref="pddGoodsLnput" @success="crud.refresh()"></pddGoodsLnput>
		<!-- 自动上品 -->
		<el-dialog title="编辑" :visible.sync="putWayVisible">
			<div>
				<el-form :model="putWayForm" ref="putWay" label-width="200px">
					<el-form-item
						label="关键词屏蔽"
						prop="keyWords"
						:rules="{
							required: true,
							message: '请输入关键词',
							trigger: 'blur'
						}"
					>
						<el-row>
							<el-col :span="12">
								<el-input
									v-model="putWayForm.keyWords"
									type="textarea"
									autosize
								></el-input>
							</el-col>
						</el-row>
						<div>备注：请输入要屏蔽的的关键词并用英文逗号隔开</div>
					</el-form-item>
					<el-form-item
						label="佣金区间"
						prop="minCommissionRate"
						:rules="{
							required: true,
							message: '请输入佣金',
							trigger: 'blur'
						}"
					>
						<el-row :gutter="20">
							<el-col :span="4">
								<el-input
									v-model="putWayForm.minCommissionRate"
									size="mini"
								></el-input>
							</el-col>
							<el-col :span="4"
								><el-input
									v-model="putWayForm.maxCommissionRate"
									size="mini"
								></el-input
							></el-col>
						</el-row>
					</el-form-item>
					<el-form-item
						label="券后价区间"
						prop="minEndPrice"
						:rules="{
							required: true,
							message: '请输入券后价',
							trigger: 'blur'
						}"
					>
						<el-row :gutter="20">
							<el-col :span="4"
								><el-input v-model="putWayForm.minEndPrice" size="mini"></el-input
							></el-col>
							<el-col :span="4"
								><el-input
									v-model="putWayForm.levelOneEndPrice"
									size="mini"
								></el-input
							></el-col>
							<el-col :span="4"
								><el-input
									v-model="putWayForm.levelTwoEndPrice"
									size="mini"
								></el-input
							></el-col>
							<el-col :span="4"
								><el-input v-model="putWayForm.maxEndPrice" size="mini"></el-input
							></el-col>
						</el-row>
					</el-form-item>
					<el-form-item
						v-if="ifJdSp == 'jd'"
						label="补贴金区间"
						prop="minCommissionRate"
						:rules="{
							required: true,
							message: '请输入补贴金区间',
							trigger: 'blur'
						}"
					>
						<el-row :gutter="20">
							<el-col :span="4">
								<el-input v-model="putWayForm.minTljMoney" size="mini"></el-input>
							</el-col>
							<el-col :span="4"
								><el-input v-model="putWayForm.maxTljMoney" size="mini"></el-input
							></el-col>
						</el-row>
					</el-form-item>
					<el-form-item
						label="上品上限"
						prop="limitSum"
						:rules="{
							required: true,
							message: '请输入上品上限',
							trigger: 'blur'
						}"
					>
						<el-row :gutter="20">
							<el-col :span="4">
								<el-input v-model="putWayForm.limitSum" size="mini"></el-input>
							</el-col>
						</el-row>
					</el-form-item>
					<el-form-item
						v-if="ifJdSp == 'jd'"
						label="补贴金比例"
						prop="tljRate"
						:rules="{
							required: true,
							message: '请输入补贴金比例',
							trigger: 'blur'
						}"
					>
						<el-row>
							<el-col :span="4"
								><el-input
									:disabled="true"
									type="number"
									:min="0"
									:max="1"
									v-model="putWayForm.tljRate"
									size="mini"
								></el-input
							></el-col>
						</el-row>
					</el-form-item>
					<el-form-item label="抓取类目数量">
						<el-row>
							<el-col :span="4">
								<el-button @click="openForm_BWBT">请选择类目</el-button>
							</el-col>
						</el-row>
					</el-form-item>
					<el-form-item>
						<el-button size="mini" @click="savePutWay">保存</el-button>
					</el-form-item>
				</el-form>
			</div>
		</el-dialog>
	</div>
</template>

<script>
import JdGoodInfo from './components/list/jd-good-info';
import couponInfo from './components/list/coupon-info';
import searchCoupon from './components/list/searchCouponJd';
import filterGstatus from '@/views/goodsMenagement/components/filterGstatus';
import { platform } from '@/dict/index';
import { Type_TLJ } from '@/dict/index';
import moment from 'moment';
import DatePicker from '@/components/common/date-picker';
import openCurd from './components/openForm_wx';
import openCurdBwbt from './components/openFormBwbt2';
import pddGoodsLnput from './components/pddGoodsLnput';

export default {
	data() {
		return {
			crud: null,
			platform: platform,
			platformIndex: '',
			mail: '',
			dou: '',
			filterSelectVal: {
				amount: 0, //劵金额
				isNine: '',
				isDouGoods: '',
				isTop: '',
				isSpecial: '',
				isTopList: '',
				isTopListLevel: '',
				isActivity: '',
				appType: ''
			},
			enterGoodsInfo: {},
			accountList: [], // 淘宝联盟列表
			fromList: [], // 平台列表
			activityList: [], // 活动列表
			typeOptions: [],
			perfaceValue_GoodInfo: 0,
			perfaceValue_Rush: 0,
			perfaceValue_Zero: 0,
			goodsTitle: '',
			actime: [],
			goodsTypeMemory: '',
			selects: {
				coupon: {},
				date: [],
				specialType: ''
			},
			goodsType: '',
			options: {
				specialTypeOp: [],
				couponMoneyStart: 0,
				couponMoneyEnd: 0,
				price1: '',
				price2: ''
			},
			typeOptions2: [],
			putWayVisible: false,
			putWayForm: {
				levelOneEndPrice: '',
				levelTwoEndPrice: '',
				minTljMoney: '', //最低补贴金
				maxTljMoney: '',
				keyWords: '',
				minCommissionRate: '', // 佣金
				maxCommissionRate: '',
				minEndPrice: '', // 券后价
				maxEndPrice: '', // 券后价
				limitSum: '', //上品上线
				tljRate: 0 // 补贴金比例
			},
			ifJdSp: 'jd', // 是拼多多还是京东 自动上品
		};
	},
	components: {
		JdGoodInfo,
		couponInfo,
		// eslint-disable-next-line
		searchCoupon,
		filterGstatus,
		DatePicker,
		openCurd,
		openCurdBwbt,
		pddGoodsLnput
	},
	created() {
		this.getType();
	},
	methods: {
		getType() {
			this.$service.goodsMenagement.specialClassify
				.page({
					page: 1,
					size: 60,
					sort: 'asc',
					order: 'level',
					specialType: 104
				})
				.then(res => {
					var temp = res.list;
					var target = [];
					for (var i = 0; i < temp.length; i++) {
						target[i] = { label: temp[i].mainName, value: temp[i].floorId };
					}
					this.options.specialClassify = target;
				});
		},
		setGoodsort(item) {
			const self = this;
			console.log(item);
			let isActivity = 0;
			if (item.activityId == 0) {
				isActivity = 0;
			} else {
				isActivity = 1;
			}

			let app = this.$refs['cl-form'].open({
				title: '修改',
				props: {
					'label-width': '180px',
					width: '570px',
					center: true,
					'custom-class': 'custom-class-dialog-mini'
				},
				items: [
					{
						prop: 'skuImage',
						label: '商品主图：',
						span: 24,
						value: item.skuImage,
						component: {
							name: 'cl-upload'
						}
					},
					{
						prop: 'skuName',
						label: '商品标题',
						span: 24,
						value: item.skuName,
						component: {
							name: 'el-input',
							attrs: {
								size: 'mini'
							}
						}
					},
					{
						prop: 'cid',
						label: '商品分类',
						value: item.cid,
						component: {
							name: 'el-select',
							props: {
								placeholder: '商品分类'
							},
							options: self.options.specialTypeOp
						}
					},
					{
						label: '已抢数',
						prop: 'defNum',
						value: item.defNum,
						component: {
							name: 'el-input-number',
							props: {}
						},
						rules: {
							required: true,
							message: '已抢数不能为空'
						}
					},
					{
						prop: 'level',
						label: '排序值',
						span: 24,
						value: item.level,
						component: {
							name: 'level-input',
							data() {
								return {
									value2: 0
								};
							},
							props: {
								value: [String, Number]
							},
							mounted() {
								this.value2 = this.value;
							},
							methods: {
								input(e) {
									this.$emit('input', e);
								}
							},
							render() {
								return (
									<div style="display:flex">
										<el-input-number
											controls-position="right"
											min={0}
											max={100000}
											onInput={this.input}
											v-model={this.value2}></el-input-number>
										<span style="color:red;margin-left:10px">
											* 序号越大，排序越靠前
										</span>
									</div>
								);
							}
						},
						rules: [{ required: true, message: '排序不能为空', trigger: 'blur' }]
					},
					{
						prop: 'defNum',
						label: '商品基数',
						span: 11,
						value: item.defNum,
						component: {
							name: 'el-input-number',
							props: {
								min: 0
							}
						},
						rules: {
							required: true
						}
					},
					{
						label: '是否开启限时秒杀置顶',
						prop: 'isTopListLevel',
						value: item.isTopListLevel,
						component: {
							name: 'isTopList',
							data() {
								return {
									value2: 0,
									isTop: 1,
									isShow: true
								};
							},
							props: {
								value: null
							},
							mounted() {
								this.value2 = this.value;
								if (this.value == 0) {
									this.isTop = 0;
									this.isShow = false;
									this.$emit('input', 0);
								} else {
									this.isTop = 1;
									this.isShow = true;
								}
							},
							methods: {
								input(e) {
									this.$emit('input', e);
								},
								chanheSwitch(e) {
									this.isShow = e;
									if (!e) {
										this.$emit('input', 0);
									}
								}
							},
							render() {
								return (
									<div style="display:flex;align-items: center;">
										<el-switch
											v-model={this.isTop}
											active-value={1}
											onChange={this.chanheSwitch}></el-switch>
										{this.isShow && (
											<div style="margin:0 10px">
												<el-input-number
													v-model={this.value2}
													controls-position="right"
													onInput={this.input}
													min={0}
													max={10000}></el-input-number>
												<span style="color:#999999;">
													序号越大，排序越靠前
												</span>
											</div>
										)}
									</div>
								);
							}
						}
					},
					{
						prop: 'status',
						label: '是否上架',
						span: 24,
						value: item.status,
						component: {
							name: 'el-radio-group',
							options: [
								{
									label: '上架',
									value: 1
								},
								{
									label: '下架',
									value: 2
								}
							]
						}
					},
					{
						prop: 'top',
						label: '是否置顶：',
						value: item.top,
						component: {
							name: 'el-radio-group',
							options: [
								{
									label: '是',
									value: 1
								},
								{
									label: '否',
									value: 0
								}
							]
						}
					},
					{
						prop: 'isSpecial',
						label: '是否限时秒杀：',
						hidden: true,
						value: item.isSpecial,
						component: {
							name: 'el-radio-group',
							options: [
								{
									label: '是',
									value: 1
								},
								{
									label: '否',
									value: 0
								}
							]
						}
					},
					{
						prop: 'isTopList',
						label: '是否限时秒杀：',
						value: item.isTopList,
						component: {
							name: 'el-radio-group',
							options: [
								{
									label: '是',
									value: 1
								},
								{
									label: '否',
									value: 0
								}
							]
						}
					},
					{
						label: '是否活动商品',
						prop: 'isActivity',
						value: isActivity,
						component: {
							name: 'el-radio-group',
							options: [
								{
									label: '是',
									value: 1
								},
								{
									label: '否',
									value: 0
								}
							],
							on: {
								change: val => {
									if (val == 1) {
										app.hiddenItem('activityId', false);
									} else {
										app.hiddenItem('activityId', true);
									}
								}
							}
						}
					},
					{
						prop: 'activityId',
						label: '归属活动',
						hidden: item.activityId == 0 ? true : false,
						value: item.activityId == 0 ? '' : String(item.activityId),
						component: {
							name: 'el-select',
							props: {
								placeholder: '归属活动'
							},
							options: self.activityList
						},
						rules: [
							{
								required: true,
								message: '请选择归属活动',
								trigger: 'blur'
							}
						]
					}
				],
				on: {
					submit({ data, close }) {
						if (data.isActivity == 0) {
							data.activityId = 0;
						}
						delete data.isActivity;
						self.$service.jd.jdActivityGoods
							.update({
								...data,
								id: item.id
							})
							.then(() => {
								self.$message({
									message: '设置成功',
									type: 'success'
								});
								self.crud.refresh();
								close();
								return;
							})
							.catch(err => {
								self.$message.error(err);
							});
					}
				}
			});
		},
		onLoad({ ctx, app }) {
			const self = this;
			this.crud = app;
			ctx.service(this.$service.jd.jdActivityGoods)
				.set('dict', {
					api: {
						info: 'detail'
					}
				})
				.set('table', {
					columns: [
						{
							label: '序号',
							type: 'index',
							align: 'center',
							width: 80
						},
						{
							label: '商品信息',
							prop: 'goodInfo',
							align: 'left',
							'min-width': 400
						},
						{
							label: '优惠券信息',
							prop: 'couponInfo',
							align: 'left',
							'min-width': 300
						},
						{
							label: '是否榜单好货置顶',
							prop: 'isTopListLevel',
							align: 'center'
						},
						{
							label: '已抢数',
							prop: 'defNum',
							align: 'center',
							sortable: 'custom',
							'min-width': 100
						},
						{
							label: '活动类型',
							prop: 'type',
							align: 'center',
							width: 100
						},
						{
							label: '出单量',
							prop: 'orderNum',
							align: 'center',
							sortable: 'custom',
							emptyText: '0',
							'min-width': 100
						},
						{
							label: '商品排序',
							prop: 'level',
							align: 'center',
							sortable: 'custom',
							emptyText: '0',
							'min-width': 100
						},
						{
							label: '是否活动商品',
							prop: 'activityId',
							align: 'center'
						},
						{
							label: '佣金比例',
							prop: 'commissionRate',
							align: 'center',
							emptyText: '0',
							'min-width': 100
						},
						{
							label: '数据统计',
							prop: 'count',
							align: 'center',
							'min-width': 150
						},
						{
							label: '活动时间',
							prop: 'date',
							align: 'center',
							'min-width': 250
						},
						{
							label: '是否下架',
							prop: 'status',
							align: 'center'
						},
						{
							label: '是否限时秒杀',
							prop: 'isTopList',
							align: 'center'
						},
						{
							label: '平台',
							prop: 'app',
							align: 'center'
						}
					],

					op: {
						props: {
							width: 140
						},
						layout: [
							'slot-setFree',
							'slot-setSort',
							'slot-setBillion',
							'slot-setTime',
							'slot-zero'
						]
					}
				})
				.set('upsert', {
					props: {
						labelWidth: '120px',
						center: true,
						'custom-class': 'custom-class-dialog'
					},
					items: [
						{
							prop: 'skuImage',
							label: '商品主图：',
							component: {
								name: 'cl-upload'
							}
						},
						{
							prop: 'skuName',
							label: '商品标题',
							component: {
								name: 'el-input',
								attrs: {
									size: 'mini',
									placeholder: '请输入商品标题'
								}
							}
						},
						{
							prop: 'url',
							props: {
								labelWidth: '0px'
							},
							component: {
								name: 'search-counpon0',
								methods: {
									input(e) {
										this.$emit('input', e);
										app.setForm('defNum', e.sale);
									},
									onCoupon(e) {
										console.log(e);
										self.selects.coupon = e;
									},
									onJmoney(e) {
										app.setForm('jljMoney', e);
									},
									Goodsinfo(e) {
										app.setForm('defNum', e.sale);
									}
								},
								render() {
									return (
										<searchCoupon
											onGoodsInfo={this.Goodsinfo}
											onInput={this.input}
											onCoupon={this.onCoupon}
											on-jmoney={this.onJmoney}
											item={self.enterGoodsInfo}
											platform={'jd'}></searchCoupon>
									);
								}
							},
							rules: [{ required: true, message: '请先检索商品', trigger: 'blur' }]
						},
						{
							prop: 'type',
							value: '5',
							label: '活动类型',
							component: {
								name: 'el-select',
								props: {
									placeholder: '请选择活动类型',
									clearable: true
								},
								options: [
									{
										label: '零元购',
										value: '0'
									},
									{
										label: '限时抢购',
										value: '1'
									},
									{
										label: '新人专享',
										value: '2'
									},
									{
										label: '百亿补贴',
										value: '3'
									},
									{
										label: '大转盘',
										value: '4'
									},
									{
										label: '微信京礼金',
										value: '5'
									}
								]
							},
							rules: [
								{
									required: true,
									message: '请选择商品类型',
									trigger: 'blur'
								}
							]
						},
						{
							prop: 'cid',
							label: '商品分类',
							component: {
								name: 'el-select',
								props: {
									placeholder: '商品分类'
								},
								options: []
							},
							rules: [
								{
									required: true,
									message: '请选择商品分类',
									trigger: 'blur'
								}
							]
						},
						{
							label: '商品基数',
							prop: 'defNum',
							value: 0,
							component: {
								name: 'el-input-number',
								props: {}
							},
							rules: {
								required: true,
								message: '商品基数不能为空'
							}
						},
						{
							label: '京礼金总数',
							prop: 'total',
							value: 1,
							component: {
								name: 'el-input-number',
								props: {
									min: 0
								},
								on: {
									change(val) {
										let num = app.getForm('jljMoney');
										app.setForm('jljTotal', val * num);
									}
								}
							},
							rules: {
								required: true,
								message: '京礼金总数不能为空'
							}
						},
						{
							label: '京礼金金额',
							prop: 'jljMoney',
							value: 1,
							component: {
								name: 'el-input-number',
								props: {
									min: 0
								},
								on: {
									change(val) {
										let num = app.getForm('total');
										if (val == 0) {
											app.hiddenItem('jljTotal', true);
										} else {
											app.hiddenItem('jljTotal', false);
											app.setForm('jljTotal', val * num);
										}
									}
								}
							},
							rules: {
								required: true,
								message: '京礼金金额不能为空'
							}
						},
						{
							label: '京礼金总金额',
							prop: 'jljTotal',
							value: 1,
							hidden: false,
							component: {
								name: 'el-input',
								props: {
									disabled: true
								}
							},
							rules: {
								required: true,
								trigger: ['blur', 'change'],
								validator: (rule, value, callback) => {
									if (value >= 50) {
										callback();
									} else {
										callback(new Error('京礼金总金额需大于50'));
									}
								}
							}
						},
						{
							label: '活动时间',
							prop: '_date',
							value: [
								moment()
									.add(1, 'days')
									.format('YYYY-MM-DD 00:00:00'),
								moment()
									.add(1, 'days')
									.format('YYYY-MM-DD 23:59:59')
							],
							component: {
								name: 'el-date-picker',
								props: {
									'value-format': 'yyyy-MM-dd HH:mm:ss',
									type: 'datetimerange'
								}
							},
							rules: {
								required: true,
								message: '活动时间不能为空'
							}
						},
						{
							prop: 'level',
							label: '商品排序：',
							value: 100,
							component: {
								name: 'levels',
								data() {
									return {
										level: 100
									};
								},
								props: {
									value: [String, Number]
								},
								mounted() {
									this.level = this.value;
								},
								methods: {
									input(e) {
										this.$emit('input', e);
									}
								},
								render() {
									return (
										<div style="display:flex">
											<el-input-number
												v-model={this.level}
												controls-position="right"
												onInput={this.input}
												min={1}
												max={10000}></el-input-number>
											<span style="color:#999999;margin-left:10px">
												序号越大，排序越靠前
											</span>
										</div>
									);
								}
							}
						},
						{
							label: '使用有效日期',
							prop: 'effectiveDays',
							value: 0,
							component: {
								name: 'el-input-number',
								props: {
									min: 1,
									max: 7
								}
							},
							rules: {
								required: true,
								message: '使用有效日期不能为空'
							}
						},
						{
							label: '是否开启限时秒杀置顶',
							prop: 'isTopListLevel',
							value: 100,
							component: {
								name: 'isTopList',
								data() {
									return {
										isTop: 1,
										isShow: true
									};
								},
								props: {
									value: [String, Number]
								},
								methods: {
									input(e) {
										this.$emit('input', e);
									},
									chanheSwitch(e) {
										this.isShow = e;
										if (!e) {
											this.$emit('input', 0);
										}
									}
								},
								render() {
									return (
										<div style="display:flex;align-items: center;">
											<el-switch
												v-model={this.isTop}
												active-value={1}
												onChange={this.chanheSwitch}></el-switch>
											{this.isShow && (
												<div style="margin:0 10px">
													<el-input-number
														v-model={this.value}
														controls-position="right"
														onInput={this.input}
														min={1}
														max={10000}></el-input-number>
													<span style="color:#999999;">
														序号越大，排序越靠前
													</span>
												</div>
											)}
										</div>
									);
								}
							}
						},
						{
							prop: 'status',
							label: '商品状态：',
							value: 1,
							component: {
								name: 'el-radio-group',
								options: [
									{
										label: '上架',
										value: 1
									},
									{
										label: '下架',
										value: 2
									}
								]
							}
						},
						{
							prop: 'top',
							label: '是否置顶：',
							value: 1,
							component: {
								name: 'el-radio-group',
								options: [
									{
										label: '是',
										value: 1
									},
									{
										label: '否',
										value: 0
									}
								]
							}
						},
						{
							label: '是否绑定spu',
							prop: 'isSpu',
							value: 0,
							component: {
								name: 'el-radio-group',
								options: [
									{
										label: '是',
										value: 1
									},
									{
										label: '否',
										value: 0
									}
								]
							}
						},
						{
							label: '是否限时秒杀',
							prop: 'isSpecial',
							value: 0,
							hidden: true,
							component: {
								name: 'el-radio-group',
								options: [
									{
										label: '是',
										value: 1
									},
									{
										label: '否',
										value: 0
									}
								]
							}
						},
						{
							label: '是否限时秒杀',
							prop: 'isTopList',
							value: 0,
							component: {
								name: 'el-radio-group',
								options: [
									{
										label: '是',
										value: 1
									},
									{
										label: '否',
										value: 0
									}
								]
							}
						},
						{
							label: '是否活动商品',
							prop: 'isActivity',
							value: 0,
							component: {
								name: 'el-radio-group',
								options: [
									{
										label: '是',
										value: 1
									},
									{
										label: '否',
										value: 0
									}
								],
								on: {
									change: val => {
										if (val == 1) {
											app.hiddenItem('activityId', false);
										} else {
											app.hiddenItem('activityId', true);
										}
									}
								}
							}
						},
						{
							prop: 'activityId',
							label: '归属活动',
							hidden: true,
							component: {
								name: 'el-select',
								props: {
									placeholder: '归属活动'
								},
								options: []
							},
							rules: [
								{
									required: true,
									message: '请选择归属活动',
									trigger: 'blur'
								}
							]
						}
					],
					op: {
						visible: true,
						layout: ['confirm']
					}
				})
				.set('layout', [
					['refresh-btn', 'slot-add', 'slot-viewType', 'query', 'flex1', 'search-key'],
					['slot-filter'],
					['slot-filter2'],
					['data-table'],
					['flex1', 'pagination']
				])
				.on('close', isOpen => {
					app.hiddenItem('jljTotal', false);
					if (!isOpen) {
						// 清空商品数据
						this.enterGoodsInfo = {};
					}
				})
				.on('submit', (isOpen, data, { next }) => {
					delete data.jljTotal;
					if (data.isActivity == 0) {
						data.activityId = 0;
					}
					delete data.isActivity;
					const [startTime, endTime] = data._date || [];
					next({
						...data,
						url: data.url.url,
						couponInfo: self.selects.coupon,
						startTime,
						endTime
					});
				})
				.on('refresh', async (params, { next }) => {
					if (params.isNine === '') {
						delete params.isNine;
					}
					if (params.isDhh === '') {
						delete params.isDhh;
					}
					let { list } = await next(params);
					list.map(item => {
						item.commissionRate = (item.commissionRate || 0) + '%';
						item.sale = item.sale + '件';
					});
					let navList = await this.$service.goodsMenagement.specialClassify.page({
						page: 1,
						size: 60,
						sort: 'asc',
						order: 'level',
						specialType: 104
					});
					var target = [];
					for (var i = 0; i < navList.list.length; i++) {
						target.push({
							label: navList.list[i].mainName,
							value: navList.list[i].floorId
						});
					}
					app.setData('upsert.items[prop:cid].component.options', target);

					let activity = await this.$service.goodsMenagement.wxJdActivity.list();
					self.activityList = activity.map(i => {
						return {
							label: i.name,
							value: i.id
						};
					});
					app.setData(
						'upsert.items[prop:activityId].component.options',
						activity.map(i => {
							return {
								label: i.name,
								value: i.id
							};
						})
					);

					self.options.specialTypeOp = target;
				})
				.done();

			app.refresh({
				app: '',
				status: 1,
				startSale: 0,
				startTime: moment().format('YYYY-MM-DD 00:00:00'),
				endTime: moment().format('YYYY-MM-DD 23:59:59'),
				type: '5'
			});
		},
		jdLnput(type) {
			this.ifJdSp = type;
			this.crud.hiddenItem('total', type != 'jd');
			this.crud.hiddenItem('jljMoney', type != 'jd');
			this.crud.hiddenItem('jljTotal', type != 'jd');
			this.crud.append();
		},
		pddLnput() {
			this.$refs['pddGoodsLnput'].open();
		},
		openForm_CRUD() {
			this.$refs['cl-form2'].open({
				props: {
					title: '查看分类',
					width: '800px',
					size: 'mini'
				},
				op: {
					confirmButtonText: '保存',
					cancelButtonText: '关闭',

					layout: ['cancel'] // 同crud下的layout
				},
				items: [
					{
						props: {
							labelWidth: '0px'
						},
						component: openCurd
					}
				]
			});
		},
		// 京东配置自动上品
		async jdPutWayGoods(type) {
			this.ifJdSp = type;
			if (type == 'jd') {
				let res = await this.$service.goodsMenagement.bwbtConfig.jdWechat();
				this.putWayForm = res.config;
				this.putWayVisible = true;
			} else if (type == 'pdd') {
				let res = await this.$service.jd.pinduoduo.pddAutoSelfConfigWechat();
				this.putWayForm = res.config;
				this.putWayVisible = true;
			}
		},
		openForm_BWBT() {
			this.$refs['cl-form'].open({
				props: {
					title: '查看分类',
					width: '800px',
					size: 'mini'
				},
				op: {
					confirmButtonText: '保存',
					cancelButtonText: '关闭',

					layout: ['cancel'] // 同crud下的layout
				},
				items: [
					{
						prop: '104',
						value: this.ifJdSp == 'jd' ? 106 : 107,
						component: openCurdBwbt
					}
				]
			});
		},
		savePutWay() {
			console.log(this.ifJdSp);
			if (this.ifJdSp == 'jd') {
				this.$service.goodsMenagement.bwbtConfig
					.updateJdWechat(this.putWayForm)
					.then(res => {
						this.$message.success('保存成功！');
						this.putWayVisible = false;
					});
			} else if (this.ifJdSp == 'pdd') {
				this.$service.jd.pinduoduo.updateAutoSelfConfigPdd(this.putWayForm).then(res => {
					this.$message.success('保存成功！');
					this.putWayVisible = false;
				});
			}
		},

		refresh(data) {
			this.crud.refresh({
				...data
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.nav {
	padding: 0 10px;
	font-size: $font12;
	::v-deep .el-input-number.is-controls-right .el-input__inner {
		padding-left: 15px;
		padding-right: 20px;
	}
	::v-deep .el-input-number--mini {
		width: 71px;
	}
}
.nav-li {
	display: flex;
	align-items: center;
	margin: 0 20px;

	.el-select {
		width: 90px;
	}
	.el-input-number--mini {
		width: 100px;
	}
}
.setsort {
	color: $color-link;
	cursor: pointer;
	margin: 5px 5px 5px 15px;
	:hover {
		opacity: 0.8;
	}
}
.column-count {
	span {
		color: red;
	}
}
</style>
